<?php
namespace app\hotback\controller;
use app\admin\logic\MarkLogic;
use app\api\logic\JieriLogic;
use think\Db;
use app\service\CouponService;
use think\Request;

class SendMessage extends Base
{
	public function _initialize()
	{
		// 调用父类前置方法
		parent::_initialize();

		// 登录校验
		$this->IsLogin();
	}

	/**
	 * 优惠券列表
	 */
	public function index(Request $request)
	{
        if ($request->isAjax()){
            $list = Db::name('send_message')->select();
            $pd = ['未启用','启用'];
            foreach ($list as $key=>$value){
                $list[$key]['statuss'] = $pd[$value['status']];

            }
            $this->assign('list',$list);
            echo json_encode(['code'=>0,'msg'=>'1','data'=>$list]);
            die;
        }

        return $this->fetch();
	}

    public function dosend(Request $request){
        $param = $request->param();
        $info = Db::name('send_message')->where('id',$param['send_id'])->find();
        if (!empty($info)){
            for ($page = 1;$page<10;$page++){
                $user_list = Db::name('user')->where('is_lh',0)->page($page)->limit(9000)->column('mobile');
                if (empty($user_list)){
                    break;
                }
                $mobile_list = [];
                foreach ($user_list as $value){
                    $mobile_list[] = (string)$value;
                }
//                dump(count($mobile_list));
                $result = JieriLogic::send($info['moban_id'],$mobile_list);

            }
            echo json_encode(['code'=>0,'msg'=>'发送成功']);

        }else{
            echo json_encode(['code'=>-1,'msg'=>'暂无数据']);
        }


    }


}